package com.example.g5project.chat.model.po;

import com.baomidou.mybatisplus.annotation.TableName;
import com.example.g5project.chat.model.dto.ChatDTO;
import com.example.g5project.customer.model.po.BasePO;
import java.time.LocalDateTime;
import java.time.ZoneId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@TableName("chat")
public class ChatPO extends BasePO {

    private Integer callerId;

    private Integer counselorId;

    private LocalDateTime startTime;

    private LocalDateTime endTime;

    /**
     * 0-5
     */
    private Integer score;

    private String commentCaller;

    private String commentCounselor;


    public ChatDTO convert2DTO() {
        return ChatDTO.builder().id(id).customerId(callerId).consultantId(counselorId)
            .startTime(startTime == null ? null : getTimeStampMilli(this.startTime))
            .endTime(endTime == null ? null : getTimeStampMilli(this.endTime))
            .score(score).commentCustomer(commentCaller).commentConsultant(commentCounselor).build();
    }

    public Long getTimeStampMilli(LocalDateTime localDateTime) {
        return localDateTime == null ? null : localDateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
    }
}
